package com.example.travelgd.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.travelgd.entity.Specialty;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SpecialtyMapper extends BaseMapper<Specialty> {

    /**
     * 分页查询指定分类的特产
     */
    @Select("SELECT * FROM specialty WHERE category_id = #{categoryId} AND status = 1 " +
            "ORDER BY create_time DESC LIMIT #{offset}, #{pageSize}")
    List<Specialty> selectByCategoryWithPage(
            @Param("categoryId") Integer categoryId,
            @Param("offset") Integer offset,
            @Param("pageSize") Integer pageSize);

    /**
     * 分页查询所有启用状态的特产
     */
    @Select("SELECT * FROM specialty WHERE status = 1 " +
            "ORDER BY create_time DESC LIMIT #{offset}, #{pageSize}")
    List<Specialty> selectAllEnabledWithPage(
            @Param("offset") Integer offset,
            @Param("pageSize") Integer pageSize);

    /**
     * 查询指定分类的所有特产
     */
    @Select("SELECT * FROM specialty WHERE category_id = #{categoryId} AND status = 1 " +
            "ORDER BY create_time DESC")
    List<Specialty> selectByCategory(@Param("categoryId") Integer categoryId);

    /**
     * 查询所有启用状态的特产
     */
    @Select("SELECT * FROM specialty WHERE status = 1 ORDER BY create_time DESC")
    List<Specialty> selectAllEnabled();

    /**
     * 获取所有分类ID
     */
    @Select("SELECT DISTINCT category_id FROM specialty WHERE status = 1")
    List<Integer> getAllCategories();
}